package com.xinya.wanandroidclient.ui.square

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.xinya.wanandroidclient.Constants
import com.xinya.wanandroidclient.R
import com.xinya.wanandroidclient.base.BaseFragment
import com.xinya.wanandroidclient.databinding.FragmentNavigationBinding
import kotlin.reflect.KProperty

/**
 *
 * @ClassName:      NavigationFragment
 * @Description:     java类作用描述
 * @Author:         mhzhuxinya@163.com
 * @UpdateRemark:   更新说明：
 * @Version:        1.0
 */
class SquareFragment : BaseFragment() {

    companion object {
        private const val TAG = "SquareFragment"
    }


    private lateinit var dataBinding: FragmentNavigationBinding
    override fun initDataBinding(binding: ViewDataBinding?) {
        dataBinding = binding as FragmentNavigationBinding
    }

    override fun getLayoutId() = R.layout.fragment_navigation
    override fun init(savedInstanceState: Bundle?) {
        val navTabView = dataBinding.navTab
        val tabViewpagerView = dataBinding.tabViewpager

        tabViewpagerView.apply {
            adapter = object : FragmentStateAdapter(this@SquareFragment) {
                override fun getItemCount() = 2

                override fun createFragment(position: Int): Fragment {
                    return when (position) {
                        0 -> {
                            SquareListFragment().apply {
                                arguments = Bundle().apply {
                                    putInt("type", Constants.NAV_PROJECT)
                                }
                            }
                        }
                        else -> {
                            SquareListFragment().apply {
                                arguments = Bundle().apply {
                                    putInt("type", Constants.NAV_NAVIGATION)
                                }
                            }
                        }
                    }
                }
            }
        }
        TabLayoutMediator(navTabView, tabViewpagerView) { tab: TabLayout.Tab, position: Int ->
            when (position) {
                0 -> {
                    tab.text = "体系"
                }
                else -> {
                    tab.text = "导航"
                }
            }
        }.attach()
    }
}
